import request from '@/utils/request'

export function listMachineGroup(params) {
  return request({
    url: '/tdp/executor/group',
    method: 'get',
    params
  })
}

export function editMachineGroup(data) {
  return request({
    url: '/tdp/executor/group?c=edit',
    method: 'post',
    paramType: 'formData',
    data
  })
}

export function delMachineGroup(data) {
  return request({
    url: '/tdp/executor/group?c=del',
    method: 'post',
    paramType: 'formData',
    data
  })
}

export function listSlaveInfo(params) {
  return request({
    url: '/tdp/executor/group?c=slaveInfo',
    method: 'get',
    desc: '该组中的执行机列表',
    params
  })
}

export function listNotInGroupSlave(params) {
  return request({
    url: '/tdp/executor/group?c=notInGroupSlaveInfo',
    method: 'get',
    desc: '不在该组中的执行机列表',
    params
  })
}

export function addSlave(data, groupId) {
  return request({
    url: '/tdp/executor/group?c=addSlave&group_id=' + groupId,
    method: 'post',
    desc: '添加此执行机到执行组中',
    data
  })
}
export function delSlave(data, groupId) {
  return request({
    url: '/tdp/executor/group?c=delSlave&group_id=' + groupId,
    method: 'post',
    desc: '从执行组中删除此执行机',
    data
  })
}

export function breakSlave(params) {
  return request({
    url: '/tdp/executor?c=breakSlave',
    method: 'get',
    desc: '断开该执行机连接',
    params
  })
}

export function editSlaveInfo(data) {
  return request({
    url: '/tdp/executor?c=edit',
    method: 'post',
    paramType: 'formData',
    desc: '断开该执行机连接',
    data
  })
}

export function downloadSlaveZip() {
  const url = request.defaults.baseURL + '/static/tdp/slave.zip'
  window.open(url)
}

export function addExecutor(data) {
  return request({
    url: '/tdp/executor?c=add',
    method: 'post',
    paramType: 'formData',
    desc: '添加对此执行机的管理',
    data
  })
}

export function delExecutor(data) {
  return request({
    url: '/tdp/executor?c=del',
    method: 'post',
    paramType: 'formData',
    desc: '删除对此执行机的管理',
    data
  })
}
